package com.mediacloud.app.newsmodule.activity.military_encyclopedia

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.mediacloud.app.model.news.ArticleItem
import com.mediacloud.app.model.utils.ViewUtils
import com.mediacloud.app.newsmodule.R
import com.mediacloud.app.newsmodule.utils.NewsItemClickUtils

/**
 * 义项选择弹窗
 * @property mContext Context
 * @property shortTitle String
 * @property listData List<SimpleInfoDtoList>
 * @constructor
 */
class MeaningsDialog(context: Context) : Dialog(context, R.style.MBottomSheetDialog) {
    init {
        setContentView(R.layout.dialog_wiki_meanings)
        initView()
    }


    private fun initView() {
        findViewById<TextView>(R.id.tvBottomClose)?.setOnClickListener{dismiss()}
    }
    fun  show(articleID:Long,shortTitle: String, listData: List<SimpleInfoDtoList>){
        val tvTop = findViewById<TextView>(R.id.tvTop)
        val rvDialogMeanings = findViewById<RecyclerView>(R.id.rvDialogMeanings)
        tvTop?.text = shortTitle
        rvDialogMeanings?.layoutManager = ViewUtils.generateRecyclerLinearLayoutManager(tvTop?.context, true)
        val militaryEncyclopediaDirectoryTabAdapter = MilitaryEncyclopediaDialogMeaningAdapter()
        rvDialogMeanings?.adapter = militaryEncyclopediaDirectoryTabAdapter
        militaryEncyclopediaDirectoryTabAdapter.isCurrentId = articleID
        militaryEncyclopediaDirectoryTabAdapter.setNewData(listData)
        militaryEncyclopediaDirectoryTabAdapter.setOnItemClickListener { adapter, view, position ->
            dismiss()
            val item = adapter.getItem(position) as SimpleInfoDtoList
            if (articleID == item.articleId)
                return@setOnItemClickListener
            var articleItem = ArticleItem()
            articleItem.id = item.articleId
            articleItem.type = 37
            NewsItemClickUtils.OpenItemNewsHandle(view.context,37,articleItem,null)
        }
        show()
    }

    override fun show() {
        super.show()
        val window = window
        window?.setGravity(Gravity.BOTTOM)
        val params = window!!.attributes
        params.width = -1
        window.attributes = params
    }
}